<template>
  <div class="">
    <div class="head">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="交易类型：">
          <el-select v-model="formInline.billType" placeholder="请选择">
            <el-option v-for="item in options3" :key="item.id" :label="item.value" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="交易时间：">
          <el-date-picker :clearable="false" v-model="date" type="daterange" value-format="yyyy-MM-dd"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-input style="width: 320px" v-model="formInline.query" placeholder="请输入会员姓名/手机号/店铺名称/团购名称">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="sumit_button" @click="search">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="listBox">
      <div class="listBox_head">
        <export-excel-button title="订单交易记录" action="/groupon/money/v1/transaction/export" :params="ExportParams" />
      </div>
      <ex-table ref="table" :loading="loading" :table-column="tableColumn" :table-data="tableData"
        @pageSizeChange="handleSizeChange" @currentPageChange="handleCurrentChange">
      </ex-table>
    </div>
  </div>
</template>
<script>
  // components
  import {
    adminDict,
    grouponTransactionLs
  } from "@/api/operateActive";
  import ExportExcelButton from "@/components/ExportExcelButton/index";
  import handlePageMixin from "@/mixins/handlePageMixin";
  import {
    mapGetters
  } from "vuex";
  export default {
    name: "billList",
    components: {
      ExportExcelButton,
    },
    mixins: [handlePageMixin],
    data() {
      return {
        loading: false,
        centerDialogVisible: false,
        formInline: {
          billType: "", //交易类型
          query: "", //会员名称/手机号/交易单号/团购名称
          transactionStartTime: "", //交易开始时间
          transactionEndTime: "", //交易结束时间
        },
        sumobject: {},
        date: [],
        detailInfo: {},
        tableData: [],
        options3: [],
        fromTotalType: "PrepaidCardflow",
        tableColumn: [{
            prop: "shopName",
            label: "店铺名称",
            width: 160
          },
          {
            prop: "relevancyNo",
            label: "交易订单号",
            width: 155
          },
          {
            prop: "billTypeDict",
            label: "交易类型",
            width: 155
          },
          {
            prop: "orderMoney",
            label: "交易金额"
          },
          {
            prop: "customerName",
            label: "会员名称"
          },
          {
            prop: "phone",
            label: "手机号"
          },
          {
            prop: "grouponName",
            label: "团购名称",
            width: 120
          },
          {
            prop: "transactionTime",
            label: "交易时间"
          },
        ],
        storeList: [],
      };
    },
    computed: {
      ...mapGetters(["isChain"]),
      ExportParams() {
        const {
          id: ticketId
        } = this;
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        return params;
      },
    },
    created() {},
    mounted() {
      this.getBilltype();
      this.getList();
    },
    methods: {
      getBilltype() {
        //获取交易类型字典
        const params = {
          dictType: "merchant_groupon_bill_type",
        };
        adminDict(params).then((res) => {
          var arr = [{
            id: "",
            value: "全部",
          }, ];
          this.options3 = arr.concat(res.result[0].dictList);
          this.options3.splice(4,2)
        });
      },
      lookDetail(e) {
        console.log(e);
        this.$router.push({
          path: "/moneyManagement/bill-detail",
          query: {
            orderId: e.relevancyNo,
            type: e.billType,
          },
        });
      },
      search() {
        //搜索
        console.log(this.formInline);
        this.formInline.transactionStartTime = this.date[0];
        this.formInline.transactionEndTime = this.date[1];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      reset() {
        this.formInline = {};
        // this.formInline.fundFlow = ''
        // this.formInline.billType = ''
        this.date = [];
        this.pageOptions.pageNum = 1;
        this.$refs.table.pageOptions.pageNum = 1;
        this.getList();
      },
      getList() {
        const params = {
          ...this.pageOptions,
          ...this.formInline,
        };
        this.loading = true;
        grouponTransactionLs(params)
          .then((res) => {
            this.tableData = res.result.records;
            this.tableData.forEach((item) => {
              item.orderMoney = '￥' + item.orderMoney
            });
            this.$refs.table.pageOptions.total = res.result.total;
            this.sumobject = res.result.beeMerchantCardBillTotalDTO;
          })
          .finally(() => {
            this.loading = false;
          });
      },
      lookDetail(e) {
        this.centerDialogVisible = true;
      },
    },
  };

</script>
<style lang="scss" scoped>
  .el-card-title {
    font-size: 20px;
  }

  .head {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px 0;
  }

  .el-form--inline .el-form-item {
    margin-right: 20px;
  }

  .listBox {
    background-color: #fff;
    border-radius: 8px;
    padding: 20px 20px;
  }

  .table_list {
    display: flex;
    align-items: center;
    // border: 1px solid #DCDFE6;
    border-radius: 7px;
    width: 220px;
    margin-bottom: 10px;
  }

  .tableBox {
    width: calc(100% / 3);
    height: 36px;
    text-align: center;
    line-height: 36px;
    color: #303133;
    font-size: 14px;
    border: 1px solid #dcdfe6;
    border-right: 0;
  }

  .tableBox:first-child {
    border-radius: 7px 0px 0px 7px;
  }

  .tableBox:last-child {
    border-right: 1px solid #dcdfe6;
    border-radius: 0px 7px 7px 0px;
  }

  .spchoosetext {
    background-color: #fff4e6;
    color: #ff9300;
    // border: 1px solid #ff9300;
  }

  .listBox_head {
    margin-bottom: 20px;
    display: flex;
    justify-content: flex-end;
  }

  .sumit_button {
    color: #fff !important;
    background: #ff7b35 !important;
    border: 0;
  }

</style>
